package com.java.jiuyang.commons.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java.jiuyang.commons.dao.SysTerminalDao;
import com.java.jiuyang.commons.dao.SysTerminalManagerDao;
import com.java.jiuyang.commons.entity.GaoDeEntity;
import com.java.jiuyang.commons.entity.terminal.SysTerminal;
import com.java.jiuyang.commons.entity.terminal.SysTerminalManager;
import org.apache.http.HttpEntity;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: SysTerminalServiceImpl
 * @Description:
 * @Version: v1.0.0
 * @Author: Fu Hao
 * @Date: 2019/10/15 0015 上午 11:22
 * Modification History:
 * Date           Author      Version     Description
 * -------------------------------------------------------------
 * 2019/10/15 0015        Fu Hao      v1.0.0         创建
 */
@Service("SysTerminalService")
public class SysTerminalServiceImpl implements SysTerminalService {

    //调用高德API秘钥
    private static final String keyCode = "87d056f6e8cde7af1fac90480914bafc";

    //调用高德API查询行政区域的url
    private static final String admAddress = "https://restapi.amap.com/v3/config/district";

    //private static Logger logger = LoggerFactory.getLogger(SysMachineService.class);

    /*@Autowired
    private SystemLanguageService systemLanguageService;*/

    @Autowired
    private SysTerminalDao sysTerminalDao;

    @Autowired
    private SysTerminalManagerDao sysTerminalManager;

    /**
     * 终端基础信息查询-->查询店主信息
     * @param id 终端id
     * @return
     */
    @Override
    public SysTerminal findTerminal(String id) {
       /* if (id.isEmpty()){
            throw new BaseSystemException(systemLanguageService.getMessage(SystemResultEnums.PARAMS_VANNOT_BE_BULL.getMsg()),
                    SystemResultEnums.PARAMS_VANNOT_BE_BULL.getCode());
        }*/
       //1、查设备详情
        List<SysTerminal> sysTerminal=sysTerminalDao.findTerminal(id);
        //2、查店主详情
           //2-1查店主userID
        List<SysTerminalManager> userIdList=sysTerminalManager.findUserId(id);
           //2-1查用户名手机号，用户信息
        List<SysTerminalManager> userMsg=sysTerminalManager.findManager(userIdList);
        SysTerminal sysTerminal1= new SysTerminal();
        sysTerminal1.setSysTerminalManagers(userMsg);
        return sysTerminal1;
    }



    @Override
    public int updateMap(String id, String longitude, String latitude) {
        /*if (id.isEmpty()||longitude.isEmpty()||latitude.isEmpty()){
            throw new BaseSystemException(systemLanguageService.getMessage(SystemResultEnums.PARAMS_VANNOT_BE_BULL.getMsg()),
                    SystemResultEnums.PARAMS_VANNOT_BE_BULL.getCode());
        }*/
       return sysTerminalDao.updateMap(id,longitude,latitude);
    }

    /*终端基础信息保存*/
    @Override
    public int saveTerminal(SysTerminal sysTerminal) {
        //if (sysTerminal != null) {
            return sysTerminalDao.saveTerminal(sysTerminal);
        //}
        /*throw new BaseSystemException(systemLanguageService.getMessage(SystemResultEnums.PARAMS_VANNOT_BE_BULL.getMsg()),
                SystemResultEnums.PARAMS_VANNOT_BE_BULL.getCode());
*/
    }

    @Override
    public PageInfo selectTerminalList(Integer page, Integer size, SysTerminal sysTerminal) {
        page=(page==null?1:page);
        size=(size==null?10:size);
        PageHelper.startPage(page, size);
        System.out.println(sysTerminalDao.selectTerminalList(sysTerminal));
        return new PageInfo<>(sysTerminalDao.selectTerminalList(sysTerminal));
    }

    @Override
    public Object getGaoDeMap(String keyName) {
        return null;
    }

    @Override
    public List<GaoDeEntity> getLocalMap(String pid) {
        return null;
    }

    @Override
    public List<SysTerminal> testTerminal(String id) {
        return sysTerminalDao.testTerminal(id);
    }



}
